class Solution(object):
    def multiply(self, num1, num2):
        """
        :type num1: str
        :type num2: str
        :rtype: str
        """
        num1 = list(map(int, num1))
        num2 = list(map(int, num2))
        num1.reverse()
        num2.reverse()
        ret = [0] * (len(num1)+len(num2))
        for i in range(len(num1)):
            for j in range(len(num2)):
                ret[i+j]+=num1[i]*num2[j]
        carry = 0
        for i in range(len(ret)):
            ret[i] += carry
            carry = 0
            if ret[i]>=10:
                carry = ret[i]//10
                ret[i] = ret[i]%10
        while len(ret)!=0 and ret[-1]==0:
            ret.pop(-1)
        ret.reverse()
        return '0' if len(ret)==0 else ''.join(map(str, ret))

print(Solution().multiply("2", "2"))

